package com.example.aa_isdagram;



import java.util.ArrayList;
import java.util.WeakHashMap;


import android.preference.PreferenceManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListViewAdapterGuias extends BaseAdapter {
	private Context mContext;
	private ArrayList<WeakHashMap<String, String>> mItems;
	private LayoutInflater inflater;
	//private ImageLoader imgLoader; 
	private  SharedPreferences prefs;
	//private final ImageDownloader imageDownloader = new ImageDownloader();
	
	static final String GRAM_ID = "ID"; // parent node
	static final String GRAM_TITLE = "TITULO";
	static final String GRAM_DETAIL = "DETALLE";
		
	//static final int loader = R.drawable.loader2;
	static final int loader = R.drawable.rectangulo_gris_claro;

	
	public CustomListViewAdapterGuias(Context c, ArrayList<WeakHashMap<String, String>> items) {
		mContext = c;
		mItems = items;
		inflater = LayoutInflater.from(c);
		//imgLoader = new ImageLoader(c);
		prefs= PreferenceManager.getDefaultSharedPreferences(c);
		
	}
	@Override
	public int getCount() {
		return mItems.size();
	}
	@Override
	public Object getItem(int position) {
		return mItems.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder;
		if (convertView == null) {
			
			convertView = inflater.inflate(R.layout.guia_list_item, parent, false);
			holder = new ViewHolder();			
			
			holder.imagen = (ImageView) convertView.findViewById(R.id.imagenGuia);
			holder.guiaID = (TextView) convertView.findViewById(R.id.guiaID);
	        holder.title = (TextView) convertView.findViewById(R.id.Lugar);
	        holder.detalle = (TextView) convertView.findViewById(R.id.Detalle);
	        
			
			
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
			}
			
	
        /*
        String image_url = mItems.get(position).get(GUIA_IMAGEN_URL);
        String tguiaID=mItems.get(position).get(GRAM_ID);
        
        imgLoader.DisplayImage(image_url, loader, holder.imagen, 80);
        holder.guiaID.setText(tguiaID);	
		if (prefs.getInt("GUIA_"+tguiaID+"_FLAG_DESCARGADO",0) == 1){
			holder.botonDescarga.setImageResource(R.drawable.descargado_libreria);			
		}else{
			holder.botonDescarga.setImageResource(R.drawable.flecha_libreria);
		}
		*/
		
        holder.title.setText(Html.fromHtml(mItems.get(position).get(GRAM_TITLE)));
        //holder.detalle.setText(mItems.get(position).get(GRAM_DETAIL));	  
        
        //id.setText(mItems.get(position).get(GUIA_ID));
        return convertView;

		
		
	}
	
	static class ViewHolder {
		ImageView imagen;
		TextView guiaID;
        TextView title;
        TextView detalle;
        
	}
}	